USE [Test_Events]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spGetEventIndicatorTemplates]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spGetEventIndicatorTemplates]
GO

CREATE PROCEDURE [dbo].[spGetEventIndicatorTemplates]
AS
BEGIN
	SELECT	dbo.BaseEventIndicators.Id, 
			dbo.BaseEventIndicators.Name, 
			dbo.BaseEventIndicators.Number, 
			dbo.BaseEventIndicators.SortKey, 
			dbo.BaseEventIndicators.ControversyIndicatorId, 
			dbo.ControversyIndicators.Name AS ControversyIndicatorName, 
			dbo.ControversyIndicators.Number AS ControversyIndicatorNumber, 
			dbo.ControversyIndicators.SortKey AS ControversyIndicatorSortKey
	FROM    dbo.BaseEventIndicators 
	INNER JOIN dbo.ControversyIndicators ON dbo.BaseEventIndicators.ControversyIndicatorId = dbo.ControversyIndicators.Id
	ORDER BY ControversyIndicatorSortKey, dbo.BaseEventIndicators.SortKey
END


